namespace SinaFinanceBaseClassLibrary
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Media;

    public class AxisSysKline : UserControl
    {
        private double bottomSpan = 0.0;
        private double candleStickUnitWidth = 0.0;
        private double candleStickWidth = 0.0;
        private const int DEF_YAXISMARKCOUNT = 10;
        private const int highZindex = 20;
        private List<KPoint> kLinePoints = new List<KPoint>();
        private double leftSpan = 0.0;
        private const int lowZindex = 10;
        private double maxPrice = 0.0;
        private double minPrice = 0.0;
        private Canvas parentCanvas;
        public Point pointLeftBottom = new Point();
        public Point pointLeftTop = new Point();
        public Point pointRightBottom = new Point();
        public Point pointRightTop = new Point();
        private double rightSpan = 0.0;
        private double tickMarkAngle = 10.0;
        private double topSpan = 0.0;
        private List<string> xAxisTips = new List<string>();
        private double xAxisUnitLen = 0.0;
        private List<string> yAxisTips = new List<string>();
        private double yAxisUnitLen = 0.0;

        protected void InitUIParameters()
        {
            if ((this.yAxisTips.Count >= 1) && (this.kLinePoints.Count >= 0))
            {
                this.pointLeftTop = new Point(this.leftSpan, this.topSpan);
                this.pointRightTop = new Point(base.Width - this.rightSpan, this.topSpan);
                this.pointRightBottom = new Point(base.Width - this.rightSpan, base.Height - this.bottomSpan);
                this.pointLeftBottom = new Point(this.leftSpan, base.Height - this.bottomSpan);
                this.candleStickUnitWidth = ((base.Width - this.leftSpan) - this.rightSpan) / ((double) this.kLinePoints.Count);
                this.candleStickWidth = (this.candleStickUnitWidth * 2.0) / 3.0;
                this.yAxisUnitLen = ((base.Height - this.topSpan) - this.bottomSpan) / ((double) (this.yAxisTips.Count - 1));
                this.xAxisUnitLen = ((base.Width - this.leftSpan) - this.rightSpan) / ((double) (this.xAxisTips.Count - 1));
                this.maxPrice = Convert.ToDouble(this.yAxisTips[0]);
                this.minPrice = Convert.ToDouble(this.yAxisTips[(int) (this.yAxisTips.Count - 1)]);
            }
        }

        protected void RenderAxisFramework()
        {
            new AxisSysFramework { ParentCanvas = this.parentCanvas, PointLeftTop = this.pointLeftTop, PointRightTop = this.pointRightTop, PointRightBottom = this.pointRightBottom, PointLeftBottom = this.pointLeftBottom, XAxisUnitLen = this.xAxisUnitLen, YAxisUnitLen = this.yAxisUnitLen, XAxisMarkCount = this.xAxisTips.Count, YAxisMarkCount = 10, ControlZindex = 20 }.RenderAxisSysFramework();
        }

        protected void RenderAxisMarks()
        {
            AxisSysMarks marks = new AxisSysMarks {
                ParentCanvas = this.parentCanvas,
                TickMarkAngle = this.tickMarkAngle
            };
            marks.DrawAxisMarks(this.leftSpan, base.Height - this.bottomSpan, this.xAxisUnitLen, this.xAxisTips, XorYAxisEnum.xAxis);
            marks.IsSameColor = true;
            marks.TickMarkAngle = 0.0;
            marks.DrawAxisMarks(this.leftSpan, this.topSpan, this.yAxisUnitLen, this.yAxisTips, XorYAxisEnum.kYAxis);
        }

        public void RenderAxisSys()
        {
            this.InitUIParameters();
            this.RenderAxisFramework();
            this.RenderAxisMarks();
            this.RenderCandleSticks();
        }

        protected void RenderCandleSticks()
        {
            int num = 0;
            IEnumerator enumerator = (IEnumerator) this.kLinePoints.GetEnumerator();
            Point point = new Point();
            Point point2 = new Point();
            Point point3 = new Point();
            Point point4 = new Point();
            Point point5 = new Point();
            Point point6 = new Point();
            while (enumerator.MoveNext())
            {
                KPoint point7 = (KPoint) enumerator.Current;
                Color red = Colors.Red;
                double num2 = Convert.ToDouble(point7.DayStartPrice);
                double num3 = Convert.ToDouble(point7.DayEndPrice);
                double num4 = Convert.ToDouble(point7.DayPriceMax);
                double num5 = Convert.ToDouble(point7.DayPriceMin);
                point.X = (this.pointLeftTop.X + (this.candleStickUnitWidth / 2.0)) + (this.candleStickUnitWidth * num);
                point2.X = point.X;
                point3.X = point.X - (this.candleStickWidth / 2.0);
                point4.X = point.X + (this.candleStickWidth / 2.0);
                point5.X = point4.X;
                point6.X = point3.X;
                point.Y = this.pointLeftTop.Y + ((((base.Height - this.topSpan) - this.bottomSpan) * (this.maxPrice - num4)) / (this.maxPrice - this.minPrice));
                point2.Y = this.pointLeftTop.Y + ((((base.Height - this.topSpan) - this.bottomSpan) * (this.maxPrice - num5)) / (this.maxPrice - this.minPrice));
                if (num2 > num3)
                {
                    red = Colors.Green;
                    point3.Y = this.pointLeftTop.Y + ((((base.Height - this.topSpan) - this.bottomSpan) * (this.maxPrice - num2)) / (this.maxPrice - this.minPrice));
                    point6.Y = this.pointLeftTop.Y + ((((base.Height - this.topSpan) - this.bottomSpan) * (this.maxPrice - num3)) / (this.maxPrice - this.minPrice));
                }
                else
                {
                    point3.Y = this.pointLeftTop.Y + ((((base.Height - this.topSpan) - this.bottomSpan) * (this.maxPrice - num3)) / (this.maxPrice - this.minPrice));
                    point6.Y = this.pointLeftTop.Y + ((((base.Height - this.topSpan) - this.bottomSpan) * (this.maxPrice - num2)) / (this.maxPrice - this.minPrice));
                }
                point4.Y = point3.Y;
                point5.Y = point6.Y;
                new CandleStick { CandleStickLineTopPoint = point, CandleStickLineButtomPoint = point2, CandleStickLeftTopPoint = point3, CandleStickRightTopPoint = point4, CandleStickRightButtomPoint = point5, CandleStickLeftButtomPoint = point6, CandleColor = red, ParentCanvas = this.parentCanvas }.RenderCandleStick();
                num++;
            }
        }

        public double BottomSpan
        {
            get
            {
                return this.bottomSpan;
            }
            set
            {
                this.bottomSpan = value;
            }
        }

        public List<KPoint> KLinePoints
        {
            get
            {
                return this.kLinePoints;
            }
            set
            {
                this.kLinePoints = value;
            }
        }

        public double LeftSpan
        {
            get
            {
                return this.leftSpan;
            }
            set
            {
                this.leftSpan = value;
            }
        }

        public Canvas ParentCanvas
        {
            get
            {
                return this.parentCanvas;
            }
            set
            {
                this.parentCanvas = value;
            }
        }

        public double RightSpan
        {
            get
            {
                return this.rightSpan;
            }
            set
            {
                this.rightSpan = value;
            }
        }

        public double TopSpan
        {
            get
            {
                return this.topSpan;
            }
            set
            {
                this.topSpan = value;
            }
        }

        public List<string> XAxisTips
        {
            get
            {
                return this.xAxisTips;
            }
            set
            {
                this.xAxisTips = value;
            }
        }

        public List<string> YAxisTips
        {
            get
            {
                return this.yAxisTips;
            }
            set
            {
                this.yAxisTips = value;
            }
        }
    }
}
